<?php

namespace app\common\model;

use think\model\concern\SoftDelete;

class Robot extends \think\Model
{
    use SoftDelete;

    protected $table = 'db_robot';

    protected $jsonAssoc = true;

    protected $autoWriteTimestamp = true;

    protected $schema = [
        'id' => 'int',
        'create_time' => 'int',
        'update_time' => 'int',
        'delete_time' => 'int',
        'pubid' => 'varchar',
        'name' => 'varchar',
        'brief_introduction' => 'text',
        'welcome_message' => 'text',
        'is_train' => 'tinyint',
        'member_id' => 'int',
        'word_limit' => 'int',
        'daily_conversation_limit' => 'int',
        'is_open_api' => 'tinyint',
        'is_remove_brand' => 'tinyint',
        'daily_price' => 'double',
        'expiration_time' => 'int',
        'word_count' => 'int',
        'number_of_conversations_today' => 'int',
        'number_of_documents' => 'int',
        'number_of_likes' => 'int',
        'number_of_unlikes' => 'int',
        'is_event' => 'tinyint',
        'title' => 'varchar',
        'subtitle' => 'varchar',
        'consultation_icon' => 'varchar',
        'opening_remarks' => 'text',
        'preset_questioning_options' => 'text',
        'advanced_style_settings' => 'longtext',
        'robot_products_id' => 'int',
        'code' => 'varchar',
        'domain_name' => 'json',
        'is_enable_js' => 'tinyint',
        'is_enable_sharing' => 'tinyint',
        'share_password' => 'varchar',
        'similarity' => 'double',
        'is_gpt_answer' => 'tinyint',
        'unable_to_answer_content' => 'text',
    ];

    protected $json = [
        'domain_name',
    ];

    public $getters = [
        
    ];

    /**
     * 关联模型robotFiles
     */
    public function robotFiles()
    {
        return $this->hasMany(RobotFiles::class );
    }

    /**
     * 关联模型robotConversation
     */
    public function robotConversation()
    {
        return $this->hasMany(RobotConversation::class );
    }

    /**
     * 关联模型robotConversationMessage
     */
    public function robotConversationMessage()
    {
        return $this->hasMany(RobotConversationMessage::class );
    }

    /**
     * 关联模型robotEvent
     */
    public function robotEvent()
    {
        return $this->hasMany(RobotEvent::class );
    }

    /**
     * 关联模型openaiUsage
     */
    public function openaiUsage()
    {
        return $this->hasMany(OpenaiUsage::class );
    }

    /**
     * 关联模型robotApi
     */
    public function robotApi()
    {
        return $this->hasMany(RobotApi::class );
    }

    /**
     * 关联模型robotAnalysis
     */
    public function robotAnalysis()
    {
        return $this->hasMany(RobotAnalysis::class );
    }

    /**
     * 关联模型member
     */
    public function member()
    {
        return $this->belongsTo(Member::class );
    }

    /**
     * 关联模型robotProducts
     */
    public function robotProducts()
    {
        return $this->belongsTo(RobotProducts::class );
    }

    /**
     * 到期时间设置器
     */
    public function setExpirationTimeAttr($value, $data)
    {
        return $value?strtotime($value):0;
    }
}
